﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;

namespace DistributeTransaction.Models
{
    public class CardInfo
    {
        [Key]
        [Display(Name = "AccountId")]
        public int AccountId { get; set; }

        [Display(Name = "Holder Name")]
        public string HoldName { get; set; }

        [Required]
        [StringLength(16, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 13)]
        [Display(Name = "Card Number")]
        public string CardNumber { get; set; }

        [Display(Name = "Card Type")]
        public string CardType { get; set; }

        [Display(Name = "Expire Month")]
        [RegularExpression("^[0-9]{2}$", ErrorMessage = "Not valid Number!")]
        public string ExpireMonth { get; set; }

        [Display(Name = "Expire Year")]
        [RegularExpression("^[0-9]{2}$", ErrorMessage = "Not valid Number!")]
        public string ExpireYear { get; set; }

        [Display(Name = "Expire Date")]
        public string ExpireDate
        {
            get
            {
                return ExpireMonth + "/" + ExpireYear;
            }
        }

        [Display(Name = "Valid Code")]
        [RegularExpression("^[0-9]{3}$", ErrorMessage = "Not valid Number!")]
        public string ValidCode { get; set; }

        public IEnumerable<string> CardTypeList
        {
            get
            {
                return new List<string> { "Visa", "Master Card", "American Express", "Amex Corporate", "Discover", "JCB", "Dinners Club" };
            }
        }

        public IEnumerable<string> MonthList
        {
            get
            {
                for (int i = 1; i <= 12; ++i)
                {
                    yield return i.ToString("D2");
                }
            }
        }

        public IEnumerable<string> YearList
        {
            get
            {
                int y = DateTime.Today.Year;
                for (int i = 0; i < 20; ++i)
                {
                    yield return (y + i).ToString("D4").Substring(2);
                }
            }
        }
    }
}